#初始
'''
# 第一题
list =[1,2,3,4,5]
print(list, type(list))
# 第二题
list =[1,2,3,4,5]
list.append(6)
print(list, type(list))
# 第三题
list =[1,2,3,4,5]
del list[3]
print(list, type(list))
# 第四题
list =[1,2,3,4,5]
list[1] = 8
print(list, type(list))
# 第五题
list =[1,2,3,4,5]
index = list.index(8)
print(list, type(list))
# 第六题
list =[1,2,3,4,5]
for element in list:
    print(element)
# 第七题
list =[1,2,3,4,5]
new_list = [7,8,9]
for item in new_list:
    list.append(item)
print(list,type(list))
# 第八题
list =[1,2,3,4,5]
list.extend([10,11,12])
print(list,type(list))
# 第九题
list =[1,2,3,4,5]
print(list[2:5:1])
#第十题
list =[1,2,3,4,5]
new_list = [13,14]
list[2:3:1]= new_list
print(list,type(list))
'''

'''
#进阶题
#第一题
my_list =[3, "apple", 9, "banana", 7, "cherry", 2, "date", 5, "elderberry"]
my_list.append("fig")
print(my_list)
#第二题
my_list =[3, "apple", 9, "banana", 7, "cherry", 2, "date", 5, "elderberry"]
my_list.remove("banana")
print(my_list)
#第三题
index = my_list.index(7)
my_list[index] = "grape"
print(my_list)
#第四题
my_list =[3, "apple", 9, "banana", 7, "cherry", 2, "date", 5, "elderberry"]
index = my_list.index("cherry")
print(index)
#第五题
my_list =[3, "apple", 9, "banana", 7, "cherry", 2, "date", 5, "elderberry"]
for elment in my_list:
    print(elment)
#第六题
my_list.insert(6,"kiwi")
print(my_list)
#第七题
my_list =[3, "apple", 9, "banana", 7, "cherry", 2, "date", 5, "elderberry"]
element = my_list[2]
print(element)
#第八题
my_list =[3, "apple", 9, "banana", 7, "cherry", 2, "date", 5, "elderberry"]
element = my_list[-2]
print(element)
#第九题
my_list =[3, "apple", 9, "banana", 7, "cherry", 2, "date", 5, "elderberry"]
num = my_list[2:7:1]
for elment in num:
    print(elment)
#第十题
my_list =[3, "apple", 9, "banana", 7, "cherry", 2, "date", 5, "elderberry"]
num =my_list[::-1]
print(num)
#第十一题
my_list=[3,"apple",9,"banana","cherry",2,"date",5,"elderberry"]
#提取字符串元素
string_elements =[element for element in my_list if isinstance(element,str)]
# 对字符串元素进行排序
string_elements.sort()
#将排序后的字符串放回原列表
string_index=0
new_list =[]
for element in my_list:
       if isinstance(element,str):
           new_list.append(string_elements[string_index])
           string_index += 1
       else:
           new_list.append(element)
print("对字符串排序后且保留数字原位的列表:",new_list)
#第十二题
my_list=[3,"apple",9,"banana","cherry",2,"date",5,"elderberry"]
num = {1:'one',2:'tow',3:'three',5:'five',7:'seven',9:'nine'}
new_list = []
for element in my_list:
    if isinstance(element, int):
        new_list.append(num.get(element),str(element))
    else:
        new_list.append(element)
print(new_list)
'''

'''
#复杂题
#第一题
list = [i for i in range(2,101,2)]
print(list)
#第二题
list = [i**2 for i in range(2,101,2)]
print(list)
#第三题
list = [i**2 for i in range(2,101,2)]
list = [num for num in list if num <= 1000]
print(list)
#第四题
list = [i for i in range(2,101,2)]
m =list[::-1]
print(m)
#第五题
list = [i for i in range(2,101,2)]
m = list[:10:1]
print(m)
#第六题
list = [i for i in range(2,101,2)]
list.extend([101,102,103])
m = list[::-1]
print(m)
#第七题
m = sum(list)/len(list)
print(m)
#第八题
list = [i for i in range(2,101,2)]
m=max(list)
n=min(list)
print(m,n)
#第九题
list = [i for i in range(2,101,2)]
try:
    index = list.index(11)
    print(index)
except ValueError:
    print("没有11")
#第十题
list = [i for i in range(2,101,2)]
list_for = list.copy()
for i in range(len(list_for)):
    list_for[i] = str(list_for[i])
print(list_for)
#第十一题
list = [i for i in range(2,101,2)]
n =[float(num) for num in list]
print(n)
#第十二题
list = [i for i in range(2,101,2)]
list = [m for  m in list if m > 50]
print(list)
#第十三题
list = [i for i in range(2,101,2)]
list.insert(2,99)
print(list)
#第十四题
list = [i for i in range(2,101,2)]
del list[:-2:-1]
print(list)
#第十五题
list = [i for i in range(2,101,2)]
n = [m*2 for i in list]
print(n)
#第十六题
list = [i for i in range(2,101,2)]
n = [m for m in list if m <=50]
h = [u for u in list if u >50]
print(n)
print(h)
#第十七题
list = [i for i in range(2,101,2)]
list_dict = {value: index for index,value in enumerate(list)}
print(list_dict)
#第十八题
list = [i for i in range(2,101,2)]
for index,value in enumerate(list):
    print(index, value)
#第十九题
import random
list = [i for i in range(2,101,2)]
if list:
    n = random.choice(list)
    print(n)
else:
    print("无")
#第二十题
list = [i for i in range(2,101,2)]
try:
    with open('list.txt','w')as file:
        for num in list:
            file.write(str(num) + '\n')
    print("列表成功保存到list.txt文件中。")
except Exception as e:
    print(f"保存文件时出现错误：{e}")
    '''